﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WJP.Configuration
{
    /// <summary>
    /// 框架配置
    /// </summary>
    public class PlatformConfiguration
    {
        public PlatformConfiguration()
        {
            this.DevCulture = "zh-CN";
        }

        /// <summary>
        /// 开发语言文化代码，默认值是 zh-CN。
        /// </summary>
        public string DevCulture { get; set; }


        private PlatformSection _section;

        /// <summary>
        /// 配置节
        /// </summary>
        public PlatformSection Section
        {
            get
            {
                this.EnsureLoaded();
                return this._section;
            }
        }

        private void EnsureLoaded()
        {
            if (_section == null)
                this._section = (ConfigurationManager.GetSection("platform") as PlatformSection);
            if (_section == null)
                this._section = new PlatformSection();
        }

        /// <summary>
        /// 主配置节
        /// </summary>
        public MasterConfigElement Master
        {
            get
            {
                return this.Section.MasterConfig;
            }
        }

        /// <summary>
        /// 客户端配置
        /// </summary>
        public ClientConfigElement Client
        {
            get
            {
                return this.Section.Client;
            }
        }
    }
}
